{template 'common/header'}
    <title>编辑文章</title>
    <!-- 强制让文档的宽度与设备的宽度保持1:1，并且文档最大的宽度比例是1.0，且不允许用户点击屏幕放大浏览 -->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, minimal-ui">
    <!-- iphone设备中的safari私有meta标签，它表示：允许全屏模式浏览 -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <link rel="stylesheet" href="../addons/ewei_shop/static/ueditor/css/style.css">
    <script src="../addons/ewei_shop/static/js/dist/ajaxfileupload.js" type="text/javascript"></script>
<style type="text/css">
.myshop_sub1 {height:44px; width:94%; margin:14px 3% 0px; background:#ff4f4f; border-radius:4px; text-align:center; font-size:16px; line-height:44px; color:#fff;}
.myshop_main {height:auto;width:94%; padding:0px 3%; border-bottom:1px solid #f0f0f0; border-top:1px solid #f0f0f0; margin-top:14px; background:#fff;}
.myshop_main .line1 {height:80px; width:100%; border-bottom:1px solid #f0f0f0; line-height:80px;}
.myshop_main .line1 .label { float:left;width:70px;font-weight:bold;}
.myshop_main .line1 .info { float:right; width:100%; margin-left:-75px;;overflow:hidden;height:80px;}
.myshop_main .line1 .info .inner { color:#666;margin-left:75px;padding-top:10px;}
.myshop_main .line1 .info .inner .plus { float:left;width:60px;height:60px;border:1px solid #efefef; color:#efefef;; font-size:45px;line-height:55px;text-align:center;}
.myshop_main .line1 .info .inner .plus1 { float:left;width:90%;height:60px;border:1px solid #efefef; color:#efefef;; font-size:45px;line-height:55px;text-align:center;}

.myshop_main .line1 .info .inner .preview0 { position:absolute; width:60px;height:60px;z-index:2}
.myshop_main .line1 .info .inner .preview1 { position:absolute; width:90%;height:60px;z-index:2}

.myshop_main .line1 .info .inner .preview0 img,.myshop_main .line1 .info .inner .preview1 img { width:100%;height:100%;}
textarea {height:150px;line-height:22px; width:100%;padding:5px;font-size:13px; background:#fff; padding-left:2%; border:1px solid #e9e9e9; margin:14px 0px 0; -webkit-appearance: none;}

.myshop_menu {height:44px; background:#fff;}
.myshop_menu .nav {height:44px; width:50%; border-bottom:1px solid #f1f1f1;background:#fff; border-left:1px solid #f1f1f1; float:left; line-height:44px; font-size:14px; color:#666; text-align:center;}
.myshop_menu .navon {height:42px; color:#ff771b; border-bottom:2px solid #ff771b;}
</style>
<div id='container'></div>
<div class="page_topbar">
    <a href="{php echo $this->createPluginMobileUrl('commission/myshop/activity_list')}" class="back" ><i class="fa fa-angle-left"></i></a>
    <div class="title">编辑文章</div>
</div>
<div class="myshop_menu">
        <div class="nav navon" style="border-left:0px;width:49%;" onclick="location.href='{php echo $this->createPluginMobileUrl('commission/editor_article',array('op'=>'editor'))}'">编辑文章</div>
        <div class="nav"  onclick="location.href='{php echo $this->createPluginMobileUrl('commission/editor_article')}'">我的文章</div>
</div>
    <div style="width:100%;margin: 0 auto;">
       <div class="myshop_main">
        <div class="line1">
            <div class="label">封面图片</div>
            <div class="info">
                <div class="inner">
                    <div class="plus" style="position:relative;">
                        <input type="file" data-tag="0" name='imgFile0' id='imgFile0' style="position:absolute;left:0;z-index:3;width:60px;height:60px;-webkit-tap-highlight-color: transparent;filter:alpha(Opacity=0); opacity: 0;" />
                        <i class="fa fa-plus"  style="position:absolute;top:10px;right:12px;z-index:1"></i>
                        <div id="preview0" class="preview0">
                            <img src="{$info['image']}"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" id="img0" value="{$info['article_img']}" />
       </div>
        <div class="publish-article-title">
            <div class="title-tips">标题</div>
            <input type="text" id="title" class="w100" placeholder="文章标题" style="width:100%;" value="{$info['article_title']}">
        </div>
        <div class="publish-article-content">
            <div class="title-tips">正文</div>
            <div class="article-content" id="content">{$info['article_content']}</div>
        </div>
    </div>
    <div class="myshop_sub1" id='disabled' style="background:#888888;">确认</div>
    <div class="myshop_sub1" id='myshop_submit' style="display:none;">确认</div>
     <script id="tpl_img" type="text/html">
     <img src='<%url%>' tag="<%tag%>" img='<%filename%>'/>
     </script>
    <script src="../addons/ewei_shop/static/ueditor/artEditor.min.js"></script>
<script language="javascript">
    require(['tpl', 'core'], function(tpl, core){
                            function checkForm(){
                                var inputs=$(":input");
                                for(var i=1;i<inputs.length;i++)   {  
                                      if(inputs[i].value==""||inputs[i].value==null){
                                      return false;
                                      }  
                                }
                            }
                            function checkdate(){
                                var check=checkForm();
                                var content=document.getElementById("content").innerHTML;
                                if(check != false && content != '<p>请输入文章正文内容</p>' && content!=""){
                                $("#disabled").hide();
                                $("#myshop_submit").show();
                                }else{
                                $("#disabled").show();
                                $("#myshop_submit").hide();
                                }
                            }
                            $('#img0').unbind('keyup').keyup(function(){
                            checkdate();
                            });
                            $('#title').unbind('keyup').keyup(function(){
                            checkdate();
                            });
                            $('#content').unbind('keyup').keyup(function(){
                            checkdate();
                            });
                            
                            $('#myshop_submit').click(function(){
                               if($(this).attr('saving')=='1'){
                                   return;
                               }
                                $(this).html('正在处理...').attr('saving',1);
                                if($('#img0').isEmpty()){
                                    core.tip.show('请上传封面图片！');
                                    return;
                                }
                                if($('#title').isEmpty()){
                                    core.tip.show('请填写文章标题!');
                                    return;
                                }
                                var content=document.getElementById("content").innerHTML;
                                if(content=="<p>请输入文章正文内容</p>"  && content!=""){
                                    core.tip.show('请填写文章内容!');
                                    return;
                                }
                                var data = {
                                        article_img: $('#img0').val(),
                                        article_title: $('#title').val(),
                                        article_id: "{$_GPC['id']}",
                                        article_content: content
                                }
                                core.pjson('commission/editor_article',{
                                    op:'editor',
                                    data:data
                                 },function(postjson){
                                     if(postjson.status==1){
                                     location.href='{php echo $this->createPluginMobileUrl('commission/editor_article')}&op=detail&id='+postjson.result.article_id;
                                     }
                                     else{
                                         $(this).html('确认').removeAttr('saving');
                                          core.tip.show('操作失败');    
                                     }
                                },true,true);
                           }); 
        
                            $(function() {
                                "use strict";
                                $('#content').artEditor({
                                    imgTar: '#imageUpload',
                                    limitSize: 5,   // 兆
                                    showServer: false,
                                    uploadUrl: '',
                                    data: {},
                                    uploadField: 'image',
                                    placeholader: '<p>请输入文章正文内容</p>',
                                    validHtml: ["br"],
                                    uploadSuccess: function(res) {
                                        return res.path;
                                    },
                                    uploadError: function(res) {
                                        console.log(res);
                                    }
                                });
                            });
                    $('.plus input').change(function(){
                        core.loading('正在上传');
                        var tag =$(this).data('tag');
                        $.ajaxFileUpload({
                            url: core.getUrl('util/uploader_article'),
                            data: {file: "imgFile" + tag},
                            secureuri: false, 
                            fileElementId: 'imgFile'+ tag, 
                            dataType: 'json', 
                            success: function(res, status) {
                                core.removeLoading();
                                var obj = $(tpl('tpl_img', res));
                                $('.preview' + tag).html(obj);
                                $('#img' + tag).val( res.filename );
                            }, error: function(data, status, e) {
                                core.removeLoading();
                                core.tip.show('上传失败!');
                            }
                        });
                    });
    })
    </script>
{template 'common/footer'}